﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MuaChung.Models
{
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://tempuri.org/")]
    public partial class ContactInfo
    {

        private string diaChiField;

        private string soDienThoaiField;

        private string emailField;

        /// <remarks/>
        public string DiaChi
        {
            get
            {
                return this.diaChiField;
            }
            set
            {
                this.diaChiField = value;
            }
        }

        /// <remarks/>
        public string SoDienThoai
        {
            get
            {
                return this.soDienThoaiField;
            }
            set
            {
                this.soDienThoaiField = value;
            }
        }

        /// <remarks/>
        public string Email
        {
            get
            {
                return this.emailField;
            }
            set
            {
                this.emailField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://tempuri.org/")]
    public partial class TransportType
    {

        private string maHinhThucVanChuyenField;

        private string tenHinhThucVanChuyenField;

        private float giaField;

        private string donViTienField;

        /// <remarks/>
        public string MaHinhThucVanChuyen
        {
            get
            {
                return this.maHinhThucVanChuyenField;
            }
            set
            {
                this.maHinhThucVanChuyenField = value;
            }
        }

        /// <remarks/>
        public string TenHinhThucVanChuyen
        {
            get
            {
                return this.tenHinhThucVanChuyenField;
            }
            set
            {
                this.tenHinhThucVanChuyenField = value;
            }
        }

        /// <remarks/>
        public float Gia
        {
            get
            {
                return this.giaField;
            }
            set
            {
                this.giaField = value;
            }
        }

        /// <remarks/>
        public string DonViTien
        {
            get
            {
                return this.donViTienField;
            }
            set
            {
                this.donViTienField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://tempuri.org/")]
    public partial class TransportCompany
    {

        private string tenCongTyVanChuyenField;

        private string maCongTyVanChuyenField;

        private TransportType[] hinhThucVanChuyenField;

        /// <remarks/>
        public string TenCongTyVanChuyen
        {
            get
            {
                return this.tenCongTyVanChuyenField;
            }
            set
            {
                this.tenCongTyVanChuyenField = value;
            }
        }

        /// <remarks/>
        public string MaCongTyVanChuyen
        {
            get
            {
                return this.maCongTyVanChuyenField;
            }
            set
            {
                this.maCongTyVanChuyenField = value;
            }
        }

        /// <remarks/>
        public TransportType[] HinhThucVanChuyen
        {
            get
            {
                return this.hinhThucVanChuyenField;
            }
            set
            {
                this.hinhThucVanChuyenField = value;
            }
        }
    }
    public class CompanyIncome
    {        
        public DOANHNGHIEP dn;
        public decimal income;
    }
    public class DoanhNghiepModel
    {
        private static MuaChungEntities db = new MuaChungEntities();
        public static List<DOANHNGHIEP> GetAll()
        {
            try
            {
                var query = from n in db.DOANHNGHIEPs
                            select n;
                return query.ToList();
            }
            catch { return null; }
        }
        public static bool AddDoanhNghiep(DOANHNGHIEP dn)
        {
            try
            {
                if (FindByName(dn.Ten_DoanhNghiep) != null)
                {
                    return false;
                }
                db.AddToDOANHNGHIEPs(dn);
                db.SaveChanges();
                return true;
            }
            catch { return false; }
        }
        public static DOANHNGHIEP FindByName(string name)
        {
            try
            {
                var query = from n in db.DOANHNGHIEPs
                            where n.Ten_DoanhNghiep == name
                            select n;

                return query.First();
            }
            catch { return null; }
        }
        public static bool Update(DOANHNGHIEP dn)
        {
            try
            {
                db.DOANHNGHIEPs.ApplyCurrentValues(dn);
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;                
            }
        }
    }
}